package dao;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import util.Util;
import entity.Word;
import entity.WordType;

/**
 * This is the file stores the words. 
 */
public class WordDAO {
	public static final String FILE_NAME = "words.txt";

	public ArrayList<Word> findWordsByFileName(String fileName){
		ArrayList<Word> words = new ArrayList<Word>();
		
		try {
			BufferedReader br = new BufferedReader(new FileReader(fileName));
			String line = br.readLine();

			while (line != null) {
				String[] columns = line.split(",");
				String value = columns[0];
				String type = columns[1];
				
				WordType wt = Util.parseWordType(type);
				
				Word w = new Word(Word.nextId(), value, wt);
				words.add(w);
				
				line = br.readLine();
			}
			
			br.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return words;
	}
}
